/*
Copyright (c) 2006 - 2008  Universitaet Osnabrueck, virtUOS
Authors: Markus Ketterl, Johannes Emden, Nils Schuhmacher, Andreas Rickling

This file is part of virtPresenter.

virtPresenter is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

virtPresenter is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with virtPresenter.  If not, see <http://www.gnu.org/licenses/>.
*/

package virtPresenter.commands
{
	import com.adobe.cairngorm.commands.ICommand;
	import com.adobe.cairngorm.control.CairngormEvent;
	import com.adobe.cairngorm.control.CairngormEventDispatcher;
	
	import flash.events.TimerEvent;
	import flash.utils.Timer;
	
	import mx.core.Application;
	
	import virtPresenter.event.*;
	import virtPresenter.model.AdvancedScrubber;
	import virtPresenter.model.TimeStep;
	import virtPresenter.model.virtPresenterLocator;
	
	/**
	 * Command controls the speedareas.
	 * */
  	public class SpeedareaScroll implements ICommand {
				
		/**
		 * Handler for SpeedareaScrollEvent.
		 * 
		 * @see virtPresenter.event.SpeedareaScrollEvent;
		 * 
		 * */				
		
		private var thisEvent:SpeedareaScrollEvent;
		private var model:virtPresenterLocator;
		
		public function execute( event : CairngormEvent ): void {
				
			model = virtPresenterLocator.getInstance();
			thisEvent = SpeedareaScrollEvent( event );
			var step:TimeStep;
			if ( thisEvent.isBackward == true){
				if (thisEvent.intervall.match(SpeedareaScrollEvent.ANIMATIONS)){
					step = model.xmlParser.getPreviousStep(model.currentvideotime*1000);
				} else if (thisEvent.intervall.match(SpeedareaScrollEvent.SLIDES)){
					step = model.xmlParser.getPreviousSlideStep(model.currentvideotime*1000);
				} else {
					trace("Wrong intervall parameter. Choose SLIDES or ANIMATIONS: " + thisEvent.intervall);
				}
			} else{
				if (thisEvent.intervall.match(SpeedareaScrollEvent.ANIMATIONS)){
					step = model.xmlParser.getNextStep(model.currentvideotime*1000);
				} else if (thisEvent.intervall.match(SpeedareaScrollEvent.SLIDES)){
					step = model.xmlParser.getNextSlideStep(model.currentvideotime*1000);
				} else {
					trace("Wrong intervall parameter. Choose SLIDES or ANIMATIONS: " + thisEvent.intervall);
				}
			}
			model.scrubber.changeVideoPosition(step.getTime()/1000);
		}
	}	
}